RabbitMQ : Configure Cluster
2016/09/03 |
Configure RabbitMQ Cluster.
This example uses 2 RabbitMQ servers. |
|
[1] |
Install and start RabbitMQ Server on all Nodes, refer to here.
(If Firewalld is running, allow port, too) |
[2] | If Firewalld is running, allow ports for clustering. |
[root@dlp ~]# firewall-cmd --add-port={4369/tcp,25672/tcp} --permanent success [root@dlp ~]# firewall-cmd --reload success |
[3] | Configure clustering on a Node. |
# put the same cookie on all nodes. [root@node01 ~]# ssh dlp.srv.world 'cat /var/lib/rabbitmq/.erlang.cookie' > /var/lib/rabbitmq/.erlang.cookie [root@node01 ~]# systemctl restart rabbitmq-server
# stop application and reset [root@node01 ~]# rabbitmqctl stop_app Stopping node rabbit@node01 ... ...done. [root@node01 ~]# rabbitmqctl reset Resetting node rabbit@node01 ... ...done. # join in cluster (specify only hostname, not with FQDN) [root@node01 ~]# rabbitmqctl join_cluster rabbit@dlp Clustering node rabbit@node01 with rabbit@dlp ... ...done. # start application [root@node01 ~]# rabbitmqctl start_app Starting node rabbit@node01 ... ...done. # show status [root@node01 ~]# rabbitmqctl cluster_status Cluster status of node rabbit@node01 ... [{nodes,[{disc,[rabbit@dlp,rabbit@node01]}]}, {running_nodes,[rabbit@dlp,rabbit@node01]}, {cluster_name,<<"rabbit@dlp.srv.world">>}, {partitions,[]}] ...done. |
[4] | Configure Queue sync setting. This example shows to configure that Queue is synced on all Nodes. There are some modes to sync among Nodes, refer details to official site below. ⇒ http://www.rabbitmq.com/ha.html |
# add Queue for sync [root@dlp ~]# rabbitmqadmin declare queue name=shared_queue queue declared # set sync policy # rabbitmqctl set_policy [policy name(any name you like)] [Queue] [Mode] [root@dlp ~]# rabbitmqctl set_policy ha-policy "shared_queue" '{"ha-mode":"all"}' Setting policy "ha-policy" for pattern "shared_queue" to "{\"ha-mode\":\"all\"}" with priority "0" ... ...done. # show status [root@dlp ~]# rabbitmqadmin list queues name node policy slave_nodes state synchronised_slave_nodes +--------------+------------+-----------+---------------+---------+--------------------------+ | name | node | policy | slave_nodes | state | synchronised_slave_nodes | +--------------+------------+-----------+---------------+---------+--------------------------+ | shared_queue | rabbit@dlp | ha-policy | rabbit@node01 | running | rabbit@node01 | +--------------+------------+-----------+---------------+---------+--------------------------+ |
[5] | Enabling management Plugin on all Nodes, it's possbile to see each Node's status like follows. |